<%@ page contentType="text/html; charset=utf-8" language="java" pageEncoding="utf-8" %>
<%@ page import="java.sql.*, org.json.simple.*, dreampack.dataModify.*" %>
<%@ include file="/common.jsp" %>
<%
	//set Chinese Char 
	//request.setCharacterEncoding("utf-8");
	//response.setCharacterEncoding("utf-8");
	//response.setContentType("text/html; charset=utf-8");
	
	//set the content don't use cache
	//这样可以避免客户端 发送ajax请求，可能使用的是缓存数据，导致数据无效
	response.setHeader("pragma","no-cache"); 
	response.setHeader("cache-control","no-cache"); 
	response.setDateHeader("expires", -10);

	//判断用户是否具备登陆权限
	out.clear();	//这样在客户端就不会出现N多空行开头了
	JSONObject json = null;
	
	String userName = request.getParameter("username");
	String passWord = request.getParameter("password");
	if (null == userName || null == passWord) {
		json = new JSONObject();
		json.put("result", new Boolean(false));
		out.print(json);
	}
	else{
		UserType user = (UserType)UserQuery.checkUser(dreamDB, userName, passWord);
		if (null != user) {
			session.setAttribute("user", user);
			json = new JSONObject();
			json.put("username", userName);
			json.put("userrole", new Integer(user.getRole()));
			json.put("result", new Boolean(true));
			out.print(json);
		}
		else
			out.print(json);
	}
	out.flush();
%>